home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / editors / emacs / xemacs / xemacs-1.006 / xemacs-1 / lib / xemacs-19.13 / info / lispref.info-15 < prev    next >
Encoding:
GNU Info File  |  1995-09-01  |  47.0 KB  |  1,171 lines

  1. This is Info file ../../info/lispref.info, produced by Makeinfo-1.63
  2. from the input file lispref.texi.
  3.  
  4.    Edition History:
  5.  
  6.    GNU Emacs Lisp Reference Manual Second Edition (v2.01), May 1993 GNU
  7. Emacs Lisp Reference Manual Further Revised (v2.02), August 1993 Lucid
  8. Emacs Lisp Reference Manual (for 19.10) First Edition, March 1994
  9. XEmacs Lisp Programmer's Manual (for 19.12) Second Edition, April 1995
  10. GNU Emacs Lisp Reference Manual v2.4, June 1995 XEmacs Lisp
  11. Programmer's Manual (for 19.13) Third Edition, July 1995
  12.  
  13.    Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995 Free Software
  14. Foundation, Inc.  Copyright (C) 1994, 1995 Sun Microsystems, Inc.
  15. Copyright (C) 1995 Amdahl Corporation.  Copyright (C) 1995 Ben Wing.
  16.  
  17.    Permission is granted to make and distribute verbatim copies of this
  18. manual provided the copyright notice and this permission notice are
  19. preserved on all copies.
  20.  
  21.    Permission is granted to copy and distribute modified versions of
  22. this manual under the conditions for verbatim copying, provided that the
  23. entire resulting derived work is distributed under the terms of a
  24. permission notice identical to this one.
  25.  
  26.    Permission is granted to copy and distribute translations of this
  27. manual into another language, under the above conditions for modified
  28. versions, except that this permission notice may be stated in a
  29. translation approved by the Foundation.
  30.  
  31.    Permission is granted to copy and distribute modified versions of
  32. this manual under the conditions for verbatim copying, provided also
  33. that the section entitled "GNU General Public License" is included
  34. exactly as in the original, and provided that the entire resulting
  35. derived work is distributed under the terms of a permission notice
  36. identical to this one.
  37.  
  38.    Permission is granted to copy and distribute translations of this
  39. manual into another language, under the above conditions for modified
  40. versions, except that the section entitled "GNU General Public License"
  41. may be included in a translation approved by the Free Software
  42. Foundation instead of in the original English.
  43.  
  44. 
  45. File: lispref.info,  Node: Interactive Call,  Next: Command Loop Info,  Prev: Defining Commands,  Up: Command Loop
  46.  
  47. Interactive Call
  48. ================
  49.  
  50.    After the command loop has translated a key sequence into a
  51. definition, it invokes that definition using the function
  52. `command-execute'.  If the definition is a function that is a command,
  53. `command-execute' calls `call-interactively', which reads the arguments
  54. and calls the command.  You can also call these functions yourself.
  55.  
  56.  - Function: commandp OBJECT
  57.      Returns `t' if OBJECT is suitable for calling interactively; that
  58.      is, if OBJECT is a command.  Otherwise, returns `nil'.
  59.  
  60.      The interactively callable objects include strings and vectors
  61.      (treated as keyboard macros), lambda expressions that contain a
  62.      top-level call to `interactive', byte-code function objects made
  63.      from such lambda expressions, autoload objects that are declared
  64.      as interactive (non-`nil' fourth argument to `autoload'), and some
  65.      of the primitive functions.
  66.  
  67.      A symbol is `commandp' if its function definition is `commandp'.
  68.  
  69.      Keys and keymaps are not commands.  Rather, they are used to look
  70.      up commands (*note Keymaps::.).
  71.  
  72.      See `documentation' in *Note Accessing Documentation::, for a
  73.      realistic example of using `commandp'.
  74.  
  75.  - Function: call-interactively COMMAND &optional RECORD-FLAG
  76.      This function calls the interactively callable function COMMAND,
  77.      reading arguments according to its interactive calling
  78.      specifications.  An error is signaled if COMMAND is not a function
  79.      or if it cannot be called interactively (i.e., is not a command).
  80.      Note that keyboard macros (strings and vectors) are not accepted,
  81.      even though they are considered commands, because they are not
  82.      functions.
  83.  
  84.      If RECORD-FLAG is the symbol `lambda', the interactive calling
  85.      arguments for `command' are read and returned as a list, but the
  86.      function is not called on them.
  87.  
  88.      If RECORD-FLAG is `t', then this command and its arguments are
  89.      unconditionally added to the list `command-history'.  Otherwise,
  90.      the command is added only if it uses the minibuffer to read an
  91.      argument.  *Note Command History::.
  92.  
  93.  - Function: command-execute COMMAND &optional RECORD-FLAG
  94.      This function executes COMMAND as an editing command.  The
  95.      argument COMMAND must satisfy the `commandp' predicate; i.e., it
  96.      must be an interactively callable function or a keyboard macro.
  97.  
  98.      A string or vector as COMMAND is executed with
  99.      `execute-kbd-macro'.  A function is passed to
  100.      `call-interactively', along with the optional RECORD-FLAG.
  101.  
  102.      A symbol is handled by using its function definition in its place.
  103.      A symbol with an `autoload' definition counts as a command if it
  104.      was declared to stand for an interactively callable function.
  105.      Such a definition is handled by loading the specified library and
  106.      then rechecking the definition of the symbol.
  107.  
  108.  - Command: execute-extended-command PREFIX-ARGUMENT
  109.      This function reads a command name from the minibuffer using
  110.      `completing-read' (*note Completion::.).  Then it uses
  111.      `command-execute' to call the specified command.  Whatever that
  112.      command returns becomes the value of `execute-extended-command'.
  113.  
  114.      If the command asks for a prefix argument, it receives the value
  115.      PREFIX-ARGUMENT.  If `execute-extended-command' is called
  116.      interactively, the current raw prefix argument is used for
  117.      PREFIX-ARGUMENT, and thus passed on to whatever command is run.
  118.  
  119.      `execute-extended-command' is the normal definition of `M-x', so
  120.      it uses the string `M-x ' as a prompt.  (It would be better to
  121.      take the prompt from the events used to invoke
  122.      `execute-extended-command', but that is painful to implement.)  A
  123.      description of the value of the prefix argument, if any, also
  124.      becomes part of the prompt.
  125.  
  126.           (execute-extended-command 1)
  127.           ---------- Buffer: Minibuffer ----------
  128.           1 M-x forward-word RET
  129.           ---------- Buffer: Minibuffer ----------
  130.                => t
  131.  
  132.  - Function: interactive-p
  133.      This function returns `t' if the containing function (the one that
  134.      called `interactive-p') was called interactively, with the function
  135.      `call-interactively'.  (It makes no difference whether
  136.      `call-interactively' was called from Lisp or directly from the
  137.      editor command loop.)  If the containing function was called by
  138.      Lisp evaluation (or with `apply' or `funcall'), then it was not
  139.      called interactively.
  140.  
  141.      The most common use of `interactive-p' is for deciding whether to
  142.      print an informative message.  As a special exception,
  143.      `interactive-p' returns `nil' whenever a keyboard macro is being
  144.      run.  This is to suppress the informative messages and speed
  145.      execution of the macro.
  146.  
  147.      For example:
  148.  
  149.           (defun foo ()
  150.             (interactive)
  151.             (and (interactive-p)
  152.                  (message "foo")))
  153.                => foo
  154.           
  155.           (defun bar ()
  156.             (interactive)
  157.             (setq foobar (list (foo) (interactive-p))))
  158.                => bar
  159.           
  160.           ;; Type `M-x foo'.
  161.                -| foo
  162.           
  163.           ;; Type `M-x bar'.
  164.           ;; This does not print anything.
  165.           
  166.           foobar
  167.                => (nil t)
  168.  
  169. 
  170. File: lispref.info,  Node: Command Loop Info,  Next: Events,  Prev: Interactive Call,  Up: Command Loop
  171.  
  172. Information from the Command Loop
  173. =================================
  174.  
  175.    The editor command loop sets several Lisp variables to keep status
  176. records for itself and for commands that are run.
  177.  
  178.  - Variable: last-command
  179.      This variable records the name of the previous command executed by
  180.      the command loop (the one before the current command).  Normally
  181.      the value is a symbol with a function definition, but this is not
  182.      guaranteed.
  183.  
  184.      The value is copied from `this-command' when a command returns to
  185.      the command loop, except when the command specifies a prefix
  186.      argument for the following command.
  187.  
  188.  - Variable: this-command
  189.      This variable records the name of the command now being executed by
  190.      the editor command loop.  Like `last-command', it is normally a
  191.      symbol with a function definition.
  192.  
  193.      The command loop sets this variable just before running a command,
  194.      and copies its value into `last-command' when the command finishes
  195.      (unless the command specifies a prefix argument for the following
  196.      command).
  197.  
  198.      Some commands set this variable during their execution, as a flag
  199.      for whatever command runs next.  In particular, the functions for
  200.      killing text set `this-command' to `kill-region' so that any kill
  201.      commands immediately following will know to append the killed text
  202.      to the previous kill.
  203.  
  204.    If you do not want a particular command to be recognized as the
  205. previous command in the case where it got an error, you must code that
  206. command to prevent this.  One way is to set `this-command' to `t' at the
  207. beginning of the command, and set `this-command' back to its proper
  208. value at the end, like this:
  209.  
  210.      (defun foo (args...)
  211.        (interactive ...)
  212.        (let ((old-this-command this-command))
  213.          (setq this-command t)
  214.          ...do the work...
  215.          (setq this-command old-this-command)))
  216.  
  217.  - Function: this-command-keys
  218.      This function returns a vector containing the key and mouse events
  219.      that invoked the present command, plus any previous commands that
  220.      generated the prefix argument for this command. (Note: this is not
  221.      the same as in FSF Emacs, which can return a string.)  *Note
  222.      Events::.
  223.  
  224.      This function copies the vector and the events; it is safe to keep
  225.      and modify them.
  226.  
  227.           (this-command-keys)
  228.           ;; Now use `C-u C-x C-e' to evaluate that.
  229.                => [#<keypress-event control-U> #<keypress-event control-X> #<keypress-event control-E>]
  230.  
  231.  - Variable: last-command-event
  232.      This variable is set to the last input event that was read by the
  233.      command loop as part of a command.  The principal use of this
  234.      variable is in `self-insert-command', which uses it to decide which
  235.      character to insert.
  236.  
  237.      This variable is off limits: you may not set its value or modify
  238.      the event that is its value, as it is destructively modified by
  239.      `read-key-sequence'.  If you want to keep a pointer to this value,
  240.      you must use `copy-event'.
  241.  
  242.      Note that this variable is an alias for `last-command-char' in FSF
  243.      Emacs.
  244.  
  245.           last-command-event
  246.           ;; Now type `C-u C-x C-e'.
  247.                => #<keypress-event control-E>
  248.  
  249.  - Variable: last-command-char
  250.      If the value of `last-command-event' is a keyboard event, then this
  251.      is the nearest ASCII equivalent to it.  This the the value that
  252.      `self-insert-command' will put in the buffer.  Remember that there
  253.      is *not* a 1:1 mapping between keyboard events and ASCII
  254.      characters: the set of keyboard events is much larger, so writing
  255.      code that examines this variable to determine what key has been
  256.      typed is bad practice, unless you are certain that it will be one
  257.      of a small set of characters.
  258.  
  259.      This function exists for compatibility with Emacs version 18.
  260.  
  261.           last-command-char
  262.           ;; Now use `C-u C-x C-e' to evaluate that.
  263.                => 5
  264.  
  265.      The value is 5 because that is the ASCII code for `C-e'.
  266.  
  267.  - Variable: current-mouse-event
  268.      This variable holds the mouse-button event which invoked this
  269.      command, or `nil'.  This is what `(interactive "e")' returns.
  270.  
  271.  - Variable: echo-keystrokes
  272.      This variable determines how much time should elapse before command
  273.      characters echo.  Its value must be an integer, which specifies the
  274.      number of seconds to wait before echoing.  If the user types a
  275.      prefix key (say `C-x') and then delays this many seconds before
  276.      continuing, the key `C-x' is echoed in the echo area.  Any
  277.      subsequent characters in the same command will be echoed as well.
  278.  
  279.      If the value is zero, then command input is not echoed.
  280.  
  281. 
  282. File: lispref.info,  Node: Events,  Next: Reading Input,  Prev: Command Loop Info,  Up: Command Loop
  283.  
  284. Events
  285. ======
  286.  
  287.    The XEmacs command loop reads a sequence of "events" that represent
  288. keyboard or mouse activity.  Unlike in Emacs 18 and in FSF Emacs,
  289. events are a primitive Lisp type that must be manipulated using their
  290. own accessor and settor primitives.  This section describes the
  291. representation and meaning of input events in detail.
  292.  
  293.    A key sequence that starts with a mouse event is read using the
  294. keymaps of the buffer in the window that the mouse was in, not the
  295. current buffer.  This does not imply that clicking in a window selects
  296. that window or its buffer--that is entirely under the control of the
  297. command binding of the key sequence.
  298.  
  299.    For information about how exactly the XEmacs command loop works,
  300. *Note Reading Input::.
  301.  
  302.  - Function: eventp OBJECT
  303.      This function returns non-`nil' if EVENT is an input event.
  304.  
  305. * Menu:
  306.  
  307. * Event Types::            Events come in different types.
  308. * Event Contents::        What the contents of each event type are.
  309. * Event Predicates::        Querying whether an event is of a
  310.                   particular type.
  311. * Accessing Mouse Event Positions::
  312.                 Determining where a mouse event occurred,
  313.                   and over what.
  314. * Accessing Other Event Info::  Accessing non-positional event info.
  315. * Working With Events::        Creating, copying, and destroying events.
  316. * Converting Events::        Converting between events, keys, and
  317.                   characters.
  318.  
  319. 
  320. File: lispref.info,  Node: Event Types,  Next: Event Contents,  Up: Events
  321.  
  322. Event Types
  323. -----------
  324.  
  325.    Events represent keyboard or mouse activity or status changes of
  326. various sorts, such as process input being available or a timeout being
  327. triggered.  The different event types are as follows:
  328.  
  329. key-press event
  330.      A key was pressed.  Note that modifier keys such as "control",
  331.      "shift", and "alt" do not generate events; instead, they are
  332.      tracked internally by XEmacs, and non-modifier key presses
  333.      generate events that specify both the key pressed and the
  334.      modifiers that were held down at the time.
  335.  
  336. button-press event
  337. button-release event
  338.      A button was pressed or released.  Along with the button that was
  339.      pressed or released, button events specify the modifier keys that
  340.      were held down at the time and the position of the pointer at the
  341.      time.
  342.  
  343. pointer-motion event
  344.      The pointer was moved.  Along with the position of the pointer,
  345.      these events also specify the modifier keys that were held down at
  346.      the time.
  347.  
  348. misc-user event
  349.      A menu item was selected, or the scrollbar was used.
  350.  
  351. process event
  352.      Input is available on a process.
  353.  
  354. timeout event
  355.      A timeout has triggered.
  356.  
  357. magic event
  358.      Some window-system-specific action (such as a frame being resized
  359.      or a portion of a frame needing to be redrawn) has occurred.  The
  360.      contents of this event are not accessible at the E-Lisp level, but
  361.      `dispatch-event' knows what to do with an event of this type.
  362.  
  363. eval event
  364.      This is a special kind of event specifying that a particular
  365.      function needs to be called when this event is dispatched.  An
  366.      event of this type is sometimes placed in the event queue when a
  367.      magic event is processed.  This kind of event should generally
  368.      just be passed off to `dispatch-event'.  *Note Dispatching an
  369.      Event::.
  370.  
  371. 
  372. File: lispref.info,  Node: Event Contents,  Next: Event Predicates,  Prev: Event Types,  Up: Events
  373.  
  374. Contents of the Different Types of Events
  375. -----------------------------------------
  376.  
  377.    Every event, no matter what type it is, contains a timestamp (which
  378. is typically an offset in milliseconds from when the X server was
  379. started) indicating when the event occurred.  In addition, many events
  380. contain a "channel", which specifies which frame the event occurred on,
  381. and/or a value indicating which modifier keys (shift, control, etc.)
  382. were held down at the time of the event.
  383.  
  384.    The contents of each event are as follows:
  385.  
  386. key-press event
  387.     channel
  388.     timestamp
  389.     key
  390.           Which key was pressed.  This is an integer (in the printing
  391.           ASCII range: >32 and <127) or a symbol such as `left' or
  392.           `right'.  Note that many physical keys are actually treated
  393.           as two separate keys, depending on whether the shift key is
  394.           pressed; for example, the "a" key is treated as either "a" or
  395.           "A" depending on the state of the shift key, and the "1" key
  396.           is similarly treated as either "1" or "!" on most keyboards.
  397.           In such cases, the shift key does not show up in the modifier
  398.           list.  For other keys, such as `backspace', the shift key
  399.           shows up as a regular modifier.
  400.  
  401.     modifiers
  402.           Which modifier keys were pressed.  As mentioned above, the
  403.           shift key is not treated as a modifier for many keys and will
  404.           not show up in this list in such cases.
  405.  
  406. button-press event
  407. button-release event
  408.     channel
  409.     timestamp
  410.     button
  411.           What button went down or up.  Buttons are numbered starting
  412.           at 1.
  413.  
  414.     modifiers
  415.           Which modifier keys were pressed.  The special business
  416.           mentioned above for the shift key does *not* apply to mouse
  417.           events.
  418.  
  419.     x
  420.     y
  421.           The position of the pointer (in pixels) at the time of the
  422.           event.
  423.  
  424. pointer-motion event
  425.     channel
  426.     timestamp
  427.     x
  428.     y
  429.           The position of the pointer (in pixels) after it moved.
  430.  
  431.     modifiers
  432.           Which modifier keys were pressed.  The special business
  433.           mentioned above for the shift key does *not* apply to mouse
  434.           events.
  435.  
  436. misc-user event
  437.     timestamp
  438.     function
  439.           The E-Lisp function to call for this event.  This is normally
  440.           either `eval' or `call-interactively'.
  441.  
  442.     object
  443.           The object to pass to the function.  This is normally the
  444.           callback that was specified in the menu description.
  445.  
  446. process_event
  447.     timestamp
  448.     process
  449.           The Emacs "process" object in question.
  450.  
  451. timeout event
  452.     timestamp
  453.     function
  454.           The E-Lisp function to call for this timeout.  It is called
  455.           with one argument, the event.
  456.  
  457.     object
  458.           Some Lisp object associated with this timeout, to make it
  459.           easier to tell them apart.  The function and object for this
  460.           event were specified when the timeout was set.
  461.  
  462. magic event
  463.     timestamp
  464.      (The rest of the information in this event is not user-accessible.)
  465.  
  466. eval event
  467.     timestamp
  468.     function
  469.           An E-Lisp function to call when this event is dispatched.
  470.  
  471.     object
  472.           The object to pass to the function.  The function and object
  473.           are set when the event is created.
  474.  
  475. 
  476. File: lispref.info,  Node: Event Predicates,  Next: Accessing Mouse Event Positions,  Prev: Event Contents,  Up: Events
  477.  
  478. Event Predicates
  479. ----------------
  480.  
  481.    The following predicates return whether an object is an event of a
  482. particular type.
  483.  
  484.  - Function: button-event-p OBJECT OBJECT
  485.      This is true if OBJECT is a button-press or button-release event.
  486.  
  487.  - Function: button-press-event-p OBJECT
  488.      This is true if OBJECT is a mouse-button-press event.
  489.  
  490.  - Function: button-release-event-p OBJECT
  491.      This is true if OBJECT is a mouse-button-release event.
  492.  
  493.  - Function: eval-event-p OBJECT
  494.      This is true if OBJECT is an eval or misc-user event.
  495.  
  496.  - Function: key-press-event-p OBJECT
  497.      This is true if OBJECT is a key-press event.
  498.  
  499.  - Function: misc-user-event-p OBJECT
  500.      This is true if OBJECT is a misc-user event.
  501.  
  502.  - Function: motion-event-p OBJECT
  503.      This is true if OBJECT is a mouse-motion event.
  504.  
  505.  - Function: process-event-p OBJECT
  506.      This is true if OBJECT is a process event.
  507.  
  508.  - Function: timeout-event-p OBJECT
  509.      This is true if OBJECT is a timeout event.
  510.  
  511.  - Function: event-live-p OBJECT
  512.      This is true if OBJECT is any event that has not been deallocated.
  513.  
  514. 
  515. File: lispref.info,  Node: Accessing Mouse Event Positions,  Next: Accessing Other Event Info,  Prev: Event Predicates,  Up: Events
  516.  
  517. Accessing the Position of a Mouse Event
  518. ---------------------------------------
  519.  
  520.    Unlike other events, mouse events (i.e. mouse-motion, button-press,
  521. and button-release events) occur in a particular location on the screen.
  522. Many primitives are provided for determining exactly where the event
  523. occurred and what is under that location.
  524.  
  525. * Menu:
  526.  
  527. * Frame-Level Event Position Info::
  528. * Window-Level Event Position Info::
  529. * Event Text Position Info::
  530. * Event Glyph Position Info::
  531. * Event Toolbar Position Info::
  532. * Other Event Position Info::
  533.  
  534. 
  535. File: lispref.info,  Node: Frame-Level Event Position Info,  Next: Window-Level Event Position Info,  Up: Accessing Mouse Event Positions
  536.  
  537. Frame-Level Event Position Info
  538. ...............................
  539.  
  540.    The following functions return frame-level information about where a
  541. mouse event occurred.
  542.  
  543.  - Function: event-frame EVENT
  544.      This function returns the "channel" or frame that the given mouse
  545.      motion, button press, or button release event occurred in.  This
  546.      will be `nil' for non-mouse events.
  547.  
  548.  - Function: event-x-pixel EVENT
  549.      This function returns the X position in pixels of the given mouse
  550.      event.  The value returned is relative to the frame the event
  551.      occurred in.  This will signal an error if the event is not a
  552.      mouse-motion, button-press, or button-release event.
  553.  
  554.  - Function: event-y-pixel EVENT
  555.      This function returns the Y position in pixels of the given mouse
  556.      event.  The value returned is relative to the frame the event
  557.      occurred in.  This will signal an error if the event is not a
  558.      mouse-motion, button-press, or button-release event.
  559.  
  560. 
  561. File: lispref.info,  Node: Window-Level Event Position Info,  Next: Event Text Position Info,  Prev: Frame-Level Event Position Info,  Up: Accessing Mouse Event Positions
  562.  
  563. Window-Level Event Position Info
  564. ................................
  565.  
  566.    The following functions return window-level information about where
  567. a mouse event occurred.
  568.  
  569.  - Function: event-window EVENT
  570.      Given a mouse motion, button press, or button release event,
  571.      compute and return the window on which that event occurred.  This
  572.      may be `nil' if the event occurred in the border or over a
  573.      toolbar.  The modeline is considered to be in the window it
  574.      represents.
  575.  
  576.  - Function: event-buffer EVENT
  577.      Given a mouse motion, button press, or button release event,
  578.      compute and return the buffer of the window on which that event
  579.      occurred.  This may be `nil' if the event occurred in the border
  580.      or over a toolbar.  The modeline is considered to be in the window
  581.      it represents.  This is equivalent to calling `event-window' and
  582.      then calling `event-buffer' on the result if it is a window.
  583.  
  584.  - Function: event-window-x-pixel EVENT
  585.      This function returns the X position in pixels of the given mouse
  586.      event.  The value returned is relative to the window the event
  587.      occurred in.  This will signal an error if the event is not a
  588.      mouse-motion, button-press, or button-release event.
  589.  
  590.  - Function: event-window-y-pixel EVENT
  591.      This function returns the Y position in pixels of the given mouse
  592.      event.  The value returned is relative to the window the event
  593.      occurred in.  This will signal an error if the event is not a
  594.      mouse-motion, button-press, or button-release event.
  595.  
  596. 
  597. File: lispref.info,  Node: Event Text Position Info,  Next: Event Glyph Position Info,  Prev: Window-Level Event Position Info,  Up: Accessing Mouse Event Positions
  598.  
  599. Event Text Position Info
  600. ........................
  601.  
  602.    The following functions return information about the text (including
  603. the modeline) that a mouse event occurred over or near.
  604.  
  605.  - Function: event-over-text-area-p EVENT
  606.      Given a mouse-motion, button-press, or button-release event, this
  607.      function returns `t' if the event is over the the text area of a
  608.      window.  Otherwise, `nil' is returned.  The modeline is not
  609.      considered to be part of the text area.
  610.  
  611.  - Function: event-over-modeline-p EVENT
  612.      Given a mouse-motion, button-press, or button-release event, this
  613.      function returns `t' if the event is over the modeline of a window.
  614.      Otherwise, `nil' is returned.
  615.  
  616.  - Function: event-x EVENT
  617.      This function returns the X position of the given mouse-motion,
  618.      button-press, or button-release event in characters.  This is
  619.      relative to the window the event occurred over.
  620.  
  621.  - Function: event-y EVENT
  622.      This function returns the Y position of the given mouse-motion,
  623.      button-press, or button-release event in characters.  This is
  624.      relative to the window the event occurred over.
  625.  
  626.  - Function: event-point EVENT
  627.      This function returns the character position of the given
  628.      mouse-motion, button-press, or button-release event.  If the event
  629.      did not occur over a window, or did not occur over text, then this
  630.      returns `nil'.  Otherwise, it returns an index into the buffer
  631.      visible in the event's window.
  632.  
  633.  - Function: event-closest-point EVENT
  634.      This function returns the character position of the given
  635.      mouse-motion, button-press, or button-release event.  If the event
  636.      did not occur over a window or over text, it returns the closest
  637.      point to the location of the event.  If the Y pixel position
  638.      overlaps a window and the X pixel position is to the left of that
  639.      window, the closest point is the beginning of the line containing
  640.      the Y position.  If the Y pixel position overlaps a window and the
  641.      X pixel position is to the right of that window, the closest point
  642.      is the end of the line containing the Y position.  If the Y pixel
  643.      position is above a window, 0 is returned.  If it is below a
  644.      window, the value of `(window-end)' is returned.
  645.  
  646. 
  647. File: lispref.info,  Node: Event Glyph Position Info,  Next: Event Toolbar Position Info,  Prev: Event Text Position Info,  Up: Accessing Mouse Event Positions
  648.  
  649. Event Glyph Position Info
  650. .........................
  651.  
  652.    The following functions return information about the glyph (if any)
  653. that a mouse event occurred over.
  654.  
  655.  - Function: event-over-glyph-p EVENT
  656.      Given a mouse-motion, button-press, or button-release event, this
  657.      function returns `t' if the event is over a glyph.  Otherwise,
  658.      `nil' is returned.
  659.  
  660.  - Function: event-glyph-extent EVENT
  661.      If the given mouse-motion, button-press, or button-release event
  662.      happened on top of a glyph, this returns its extent; else `nil' is
  663.      returned.
  664.  
  665.  - Function: event-glyph-x-pixel EVENT
  666.      Given a mouse-motion, button-press, or button-release event over a
  667.      glyph, this function returns the X position of the pointer
  668.      relative to the upper left of the glyph.  If the event is not over
  669.      a glyph, it returns `nil'.
  670.  
  671.  - Function: event-glyph-y-pixel EVENT
  672.      Given a mouse-motion, button-press, or button-release event over a
  673.      glyph, this function returns the Y position of the pointer
  674.      relative to the upper left of the glyph.  If the event is not over
  675.      a glyph, it returns `nil'.
  676.  
  677. 
  678. File: lispref.info,  Node: Event Toolbar Position Info,  Next: Other Event Position Info,  Prev: Event Glyph Position Info,  Up: Accessing Mouse Event Positions
  679.  
  680. Event Toolbar Position Info
  681. ...........................
  682.  
  683.  - Function: event-over-toolbar-p EVENT
  684.      Given a mouse-motion, button-press, or button-release event, this
  685.      function returns `t' if the event is over a toolbar.  Otherwise,
  686.      `nil' is returned.
  687.  
  688.  - Function: event-toolbar-button EVENT
  689.      If the given mouse-motion, button-press, or button-release event
  690.      happened on top of a toolbar button, this function returns the
  691.      button.  Otherwise, `nil' is returned.
  692.  
  693. 
  694. File: lispref.info,  Node: Other Event Position Info,  Prev: Event Toolbar Position Info,  Up: Accessing Mouse Event Positions
  695.  
  696. Other Event Position Info
  697. .........................
  698.  
  699.  - Function: event-over-border-p EVENT
  700.      Given a mouse-motion, button-press, or button-release event, this
  701.      function returns `t' if the event is over an internal toolbar.
  702.      Otherwise, `nil' is returned.
  703.  
  704. 
  705. File: lispref.info,  Node: Accessing Other Event Info,  Next: Working With Events,  Prev: Accessing Mouse Event Positions,  Up: Events
  706.  
  707. Accessing the Other Contents of Events
  708. --------------------------------------
  709.  
  710.    The following functions allow access to the contents of events other
  711. than the position info described in the previous section.
  712.  
  713.  - Function: event-timestamp EVENT
  714.      This function returns the timestamp of the given event object.
  715.  
  716.  - Function: event-device EVENT
  717.      This function returns the device that the given event occurred on.
  718.  
  719.  - Function: event-key EVENT
  720.      This function returns the KeySym of the given key-press event.
  721.      This will be the ASCII code of a printing character, or a symbol.
  722.  
  723.  - Function: event-button EVENT
  724.      This function returns the button-number of the given
  725.      mouse-button-press event.
  726.  
  727.  - Function: event-modifiers EVENT
  728.      This function returns a list of symbols, the names of the modifier
  729.      keys which were down when the given mouse or keyboard event was
  730.      produced.
  731.  
  732.  - Function: event-modifier-bits EVENT
  733.      This function returns a number representing the modifier keys
  734.      which were down when the given mouse or keyboard event was
  735.      produced.
  736.  
  737.  - Function: event-function EVENT
  738.      This function returns the callback function of the given timeout,
  739.      misc-user, or eval event.
  740.  
  741.  - Function: event-object EVENT
  742.      This function returns the callback function argument of the given
  743.      timeout, misc-user, or eval event.
  744.  
  745.  - Function: event-process EVENT
  746.      This function returns the process of the given process event.
  747.  
  748. 
  749. File: lispref.info,  Node: Working With Events,  Next: Converting Events,  Prev: Accessing Other Event Info,  Up: Events
  750.  
  751. Working With Events
  752. -------------------
  753.  
  754.    XEmacs provides primitives for creating, copying, and destroying
  755. event objects.  Many functions that return events take an event object
  756. as an argument and fill in the fields of this event; or they make accept
  757. either an event object or `nil', creating the event object first in the
  758. latter case.
  759.  
  760.  - Function: allocate-event
  761.      This function returns an empty event structure.  WARNING: The event
  762.      object returned may be a reused one; see the function
  763.      `deallocate-event'.
  764.  
  765.  - Function: copy-event EVENT1 &optional EVENT2
  766.      This function makes a copy of the given event object.  If a second
  767.      argument is given, the first event is copied into the second and
  768.      the second is returned.  If the second argument is not supplied
  769.      (or is `nil') then a new event will be made as with
  770.      `allocate-event'.
  771.  
  772.  - Function: deallocate-event EVENT
  773.      This function allows the given event structure to be reused.  You
  774.      *MUST NOT* use this event object after calling this function with
  775.      it.  You will lose.  It is not necessary to call this function, as
  776.      event objects are garbage-collected like all other objects;
  777.      however, it may be more efficient to explicitly deallocate events
  778.      when you are sure that that is safe.
  779.  
  780. 
  781. File: lispref.info,  Node: Converting Events,  Prev: Working With Events,  Up: Events
  782.  
  783. Converting Events
  784. -----------------
  785.  
  786.    XEmacs provides some auxiliary functions for converting between
  787. events and other ways of representing keys.  These are useful when
  788. working with ASCII strings and with keymaps.
  789.  
  790.  - Function: character-to-event CH &optional EVENT DEVICE
  791.      This function converts a numeric ASCII value to an event structure,
  792.      replete with modifier bits.  CH is the character to convert, and
  793.      EVENT is the event object to fill in.  This function contains
  794.      knowledge about what the codes "mean" - for example, the number 9
  795.      is converted to the character Tab, not the distinct character
  796.      Control-I.
  797.  
  798.      Note that CH does not have to be a numeric value, but can be a
  799.      symbol such as `clear' or a list such as `(control backspace)'.
  800.  
  801.      If `event' is not `nil', it is modified; otherwise, a new event
  802.      object is created.  In both cases, the event is returned.
  803.  
  804.      Optional third arg DEVICE is the device to store in the event;
  805.      this also affects whether the high bit is interpreted as a meta
  806.      key.  A value of `nil' means use the selected device but always
  807.      treat the high bit as meta.
  808.  
  809.      Beware that `character-to-event' and `event-to-character' are not
  810.      strictly inverse functions, since events contain much more
  811.      information than the ASCII character set can encode.
  812.  
  813.  - Function: event-to-character EVENT &optional ALLOW-EXTRA-MODIFIERS
  814.           ALLOW-META ALLOW-NON-ASCII
  815.      This function returns the closest ASCII approximation to EVENT.
  816.      If the event isn't a keypress, this returns `nil'.
  817.  
  818.      If ALLOW-EXTRA-MODIFIERS is non-`nil', then this is lenient in its
  819.      translation; it will ignore modifier keys other than control and
  820.      meta, and will ignore the shift modifier on those characters which
  821.      have no shifted ASCII equivalent (Control-Shift-A for example,
  822.      will be mapped to the same ASCII code as Control-A).
  823.  
  824.      If ALLOW-META is non-`nil', then the Meta modifier will be
  825.      represented by turning on the high bit of the byte returned;
  826.      otherwise, `nil' will be returned for events containing the Meta
  827.      modifier.
  828.  
  829.      If ALLOW-NON-ASCII is non-`nil', then characters which are present
  830.      in the prevailing character set (*note variable
  831.      `character-set-property': Keymaps.) will be returned as their code
  832.      in that character set, instead of the return value being
  833.      restricted to ASCII.
  834.  
  835.      Note that specifying both ALLOW-META and ALLOW-NON-ASCII is
  836.      ambiguous, as both use the high bit; M-x and oslash will be
  837.      indistinguishable.
  838.  
  839.  - Function: events-to-keys EVENTS &optional NO-MICE
  840.      Given a vector of event objects, this function returns a vector of
  841.      key descriptors, or a string (if they all fit in the ASCII range).
  842.      Optional arg NO-MICE means that button events are not allowed.
  843.  
  844. 
  845. File: lispref.info,  Node: Reading Input,  Next: Waiting,  Prev: Events,  Up: Command Loop
  846.  
  847. Reading Input
  848. =============
  849.  
  850.    The editor command loop reads keyboard input using the function
  851. `next-event' and constructs key sequences out of the events using
  852. `dispatch-event'.  Lisp programs can also use the function
  853. `read-key-sequence', which reads input a key sequence at a time.  See
  854. also `momentary-string-display' in *Note Temporary Displays::, and
  855. `sit-for' in *Note Waiting::.  *Note Terminal Input::, for functions
  856. and variables for controlling terminal input modes and debugging
  857. terminal input.
  858.  
  859.    For higher-level input facilities, see *Note Minibuffers::.
  860.  
  861. * Menu:
  862.  
  863. * Key Sequence Input::        How to read one key sequence.
  864. * Reading One Event::        How to read just one event.
  865. * Dispatching an Event::        What to do with an event once it has been read.
  866. * Quoted Character Input::    Asking the user to specify a character.
  867. * Peeking and Discarding::        How to reread or throw away input events.
  868.  
  869. 
  870. File: lispref.info,  Node: Key Sequence Input,  Next: Reading One Event,  Up: Reading Input
  871.  
  872. Key Sequence Input
  873. ------------------
  874.  
  875.    Lisp programs can read input a key sequence at a time by calling
  876. `read-key-sequence'; for example, `describe-key' uses it to read the
  877. key to describe.
  878.  
  879.  - Function: read-key-sequence PROMPT
  880.      This function reads a sequence of keystrokes or mouse clicks and
  881.      returns it as a vector of events.  It keeps reading events until
  882.      it has accumulated a full key sequence; that is, enough to specify
  883.      a non-prefix command using the currently active keymaps.
  884.  
  885.      The vector and the event objects it contains are freshly created,
  886.      and will not be side-effected by subsequent calls to this function.
  887.  
  888.      The function `read-key-sequence' suppresses quitting: `C-g' typed
  889.      while reading with this function works like any other character,
  890.      and does not set `quit-flag'.  *Note Quitting::.
  891.  
  892.      The argument PROMPT is either a string to be displayed in the echo
  893.      area as a prompt, or `nil', meaning not to display a prompt.
  894.  
  895.      If the user selects a menu item while we are prompting for a key
  896.      sequence, the returned value will be a vector of a single
  897.      menu-selection event (a misc-user event).  An error will be
  898.      signalled if you pass this value to `lookup-key' or a related
  899.      function.
  900.  
  901.      In the example below, the prompt `?' is displayed in the echo area,
  902.      and the user types `C-x C-f'.
  903.  
  904.           (read-key-sequence "?")
  905.           
  906.           ---------- Echo Area ----------
  907.           ?`C-x C-f'
  908.           ---------- Echo Area ----------
  909.           
  910.                => [#<keypress-event control-X> #<keypress-event control-F>]
  911.  
  912.    If an input character is an upper-case letter and has no key binding,
  913. but its lower-case equivalent has one, then `read-key-sequence'
  914. converts the character to lower case.  Note that `lookup-key' does not
  915. perform case conversion in this way.
  916.  
  917. 
  918. File: lispref.info,  Node: Reading One Event,  Next: Dispatching an Event,  Prev: Key Sequence Input,  Up: Reading Input
  919.  
  920. Reading One Event
  921. -----------------
  922.  
  923.    The lowest level functions for command input are those which read a
  924. single event.  These functions often make a distinction between
  925. "command events", which are user actions (keystrokes and mouse
  926. actions), and other events, which serve as communication between XEmacs
  927. and the window system.
  928.  
  929.  - Function: next-event &optional EVENT PROMPT
  930.      This function reads and returns the next available event from the
  931.      window system or terminal driver, waiting if necessary until an
  932.      event is available.  Pass this object to `dispatch-event' to
  933.      handle it. If an event object is supplied, it is filled in and
  934.      returned; otherwise a new event object will be created.
  935.  
  936.      Events can come directly from the user, from a keyboard macro, or
  937.      from `unread-command-events'.
  938.  
  939.      In most cases, the function `next-command-event' is more
  940.      appropriate.
  941.  
  942.  - Function: next-command-event &optional EVENT
  943.      This function returns the next available "user" event from the
  944.      window system or terminal driver.  Pass this object to
  945.      `dispatch-event' to handle it.  If an event object is supplied, it
  946.      is filled in and returned, otherwise a new event object will be
  947.      created.
  948.  
  949.      The event returned will be a keyboard, mouse press, or mouse
  950.      release event.  If there are non-command events available (mouse
  951.      motion, sub-process output, etc) then these will be executed (with
  952.      `dispatch-event') and discarded.  This function is provided as a
  953.      convenience; it is equivalent to the Lisp code
  954.  
  955.               (while (progn
  956.                    (next-event event)
  957.                        (not (or (key-press-event-p event)
  958.                                 (button-press-event-p event)
  959.                                 (button-release-event-p event)
  960.                                 (menu-event-p event))))
  961.                  (dispatch-event event))
  962.  
  963.      Here is what happens if you call `next-command-event' and then
  964.      press the right-arrow function key:
  965.  
  966.           (next-command-event)
  967.                => #<keypress-event right>
  968.  
  969.  - Function: read-char
  970.      This function reads and returns a character of command input.  If a
  971.      mouse click is detected, an error is signalled.  The character
  972.      typed is returned as an ASCII value.  This function is retained for
  973.      compatibility with Emacs 18, and is most likely the wrong thing
  974.      for you to be using: consider using `next-command-event' instead.
  975.  
  976.  - Function: enqueue-eval-event FUNCTION OBJECT
  977.      This function adds an eval event to the back of the queue.  The
  978.      eval event will be the next event read after all pending events.
  979.  
  980. 
  981. File: lispref.info,  Node: Dispatching an Event,  Next: Quoted Character Input,  Prev: Reading One Event,  Up: Reading Input
  982.  
  983. Dispatching an Event
  984. --------------------
  985.  
  986.  - Function: dispatch-event EVENT
  987.      Given an event object returned by `next-event', this function
  988.      executes it.  This is the basic function that makes XEmacs respond
  989.      to user input; it also deals with notifications from the window
  990.      system (such as Expose events).
  991.  
  992. 
  993. File: lispref.info,  Node: Quoted Character Input,  Next: Peeking and Discarding,  Prev: Dispatching an Event,  Up: Reading Input
  994.  
  995. Quoted Character Input
  996. ----------------------
  997.  
  998.    You can use the function `read-quoted-char' to ask the user to
  999. specify a character, and allow the user to specify a control or meta
  1000. character conveniently, either literally or as an octal character code.
  1001. The command `quoted-insert' uses this function.
  1002.  
  1003.  - Function: read-quoted-char &optional PROMPT
  1004.      This function is like `read-char', except that if the first
  1005.      character read is an octal digit (0-7), it reads up to two more
  1006.      octal digits (but stopping if a non-octal digit is found) and
  1007.      returns the character represented by those digits in octal.
  1008.  
  1009.      Quitting is suppressed when the first character is read, so that
  1010.      the user can enter a `C-g'.  *Note Quitting::.
  1011.  
  1012.      If PROMPT is supplied, it specifies a string for prompting the
  1013.      user.  The prompt string is always displayed in the echo area,
  1014.      followed by a single `-'.
  1015.  
  1016.      In the following example, the user types in the octal number 177
  1017.      (which is 127 in decimal).
  1018.  
  1019.           (read-quoted-char "What character")
  1020.           
  1021.           ---------- Echo Area ----------
  1022.           What character-`177'
  1023.           ---------- Echo Area ----------
  1024.           
  1025.                => 127
  1026.  
  1027. 
  1028. File: lispref.info,  Node: Peeking and Discarding,  Prev: Quoted Character Input,  Up: Reading Input
  1029.  
  1030. Miscellaneous Event Input Features
  1031. ----------------------------------
  1032.  
  1033.    This section describes how to "peek ahead" at events without using
  1034. them up, how to check for pending input, and how to discard pending
  1035. input.
  1036.  
  1037.    See also the variables `last-command-event' and `last-command-char'
  1038. (*Note Command Loop Info::).
  1039.  
  1040.  - Variable: unread-command-events
  1041.      This variable holds a list of events waiting to be read as command
  1042.      input.  The events are used in the order they appear in the list,
  1043.      and removed one by one as they are used.
  1044.  
  1045.      The variable is needed because in some cases a function reads a
  1046.      event and then decides not to use it.  Storing the event in this
  1047.      variable causes it to be processed normally, by the command loop
  1048.      or by the functions to read command input.
  1049.  
  1050.      For example, the function that implements numeric prefix arguments
  1051.      reads any number of digits.  When it finds a non-digit event, it
  1052.      must unread the event so that it can be read normally by the
  1053.      command loop.  Likewise, incremental search uses this feature to
  1054.      unread events with no special meaning in a search, because these
  1055.      events should exit the search and then execute normally.
  1056.  
  1057.  
  1058.  - Variable: unread-command-event
  1059.      This variable holds a single event to be read as command input.
  1060.  
  1061.      This variable is mostly obsolete now that you can use
  1062.      `unread-command-events' instead; it exists only to support programs
  1063.      written for versions of XEmacs prior to 19.12.
  1064.  
  1065.  - Function: input-pending-p
  1066.      This function determines whether any command input is currently
  1067.      available to be read.  It returns immediately, with value `t' if
  1068.      there is available input, `nil' otherwise.  On rare occasions it
  1069.      may return `t' when no input is available.
  1070.  
  1071.  - Variable: last-input-event
  1072.      This variable is set to the last keyboard or mouse button event
  1073.      received.
  1074.  
  1075.      This variable is off limits: you may not set its value or modify
  1076.      the event that is its value, as it is destructively modified by
  1077.      `read-key-sequence'.  If you want to keep a pointer to this value,
  1078.      you must use `copy-event'.
  1079.  
  1080.      Note that this variable is an alias for `last-input-char' in FSF
  1081.      Emacs.
  1082.  
  1083.      In the example below, a character is read (the character `1').  It
  1084.      becomes the value of `last-input-event', while `C-e' (from the
  1085.      `C-x C-e' command used to evaluate this expression) remains the
  1086.      value of `last-command-event'.
  1087.  
  1088.           (progn (print (next-command-event))
  1089.                  (print last-command-event)
  1090.                  last-input-event)
  1091.                -| #<keypress-event 1>
  1092.                -| #<keypress-event control-E>
  1093.                => #<keypress-event 1>
  1094.  
  1095.  - Variable: last-input-char
  1096.      If the value of `last-input-event' is a keyboard event, then this
  1097.      is the nearest ASCII equivalent to it.  Remember that there is
  1098.      *not* a 1:1 mapping between keyboard events and ASCII characters:
  1099.      the set of keyboard events is much larger, so writing code that
  1100.      examines this variable to determine what key has been typed is bad
  1101.      practice, unless you are certain that it will be one of a small
  1102.      set of characters.
  1103.  
  1104.      This function exists for compatibility with Emacs version 18.
  1105.  
  1106.  - Function: discard-input
  1107.      This function discards the contents of the terminal input buffer
  1108.      and cancels any keyboard macro that might be in the process of
  1109.      definition.  It returns `nil'.
  1110.  
  1111.      In the following example, the user may type a number of characters
  1112.      right after starting the evaluation of the form.  After the
  1113.      `sleep-for' finishes sleeping, `discard-input' discards any
  1114.      characters typed during the sleep.
  1115.  
  1116.           (progn (sleep-for 2)
  1117.                  (discard-input))
  1118.                => nil
  1119.  
  1120. 
  1121. File: lispref.info,  Node: Waiting,  Next: Quitting,  Prev: Reading Input,  Up: Command Loop
  1122.  
  1123. Waiting for Elapsed Time or Input
  1124. =================================
  1125.  
  1126.    The wait functions are designed to wait for a certain amount of time
  1127. to pass or until there is input.  For example, you may wish to pause in
  1128. the middle of a computation to allow the user time to view the display.
  1129. `sit-for' pauses and updates the screen, and returns immediately if
  1130. input comes in, while `sleep-for' pauses without updating the screen.
  1131.  
  1132.    Note that in FSF Emacs, the commands `sit-for' and `sleep-for' take
  1133. two arguments to specify the time (one integer and one float value),
  1134. instead of a single argument that can be either an integer or a float.
  1135.  
  1136.  - Function: sit-for SECONDS &optional NODISP
  1137.      This function performs redisplay (provided there is no pending
  1138.      input from the user), then waits SECONDS seconds, or until input is
  1139.      available.  The result is `t' if `sit-for' waited the full time
  1140.      with no input arriving (see `input-pending-p' in *Note Peeking and
  1141.      Discarding::).  Otherwise, the value is `nil'.
  1142.  
  1143.      The argument SECONDS need not be an integer.  If it is a floating
  1144.      point number, `sit-for' waits for a fractional number of seconds.
  1145.  
  1146.      Redisplay is normally preempted if input arrives, and does not
  1147.      happen at all if input is available before it starts. (You can
  1148.      force screen updating in such a case by using `force-redisplay'.
  1149.      *Note Refresh Screen::.) If there is no input pending, you can
  1150.      force an update with no delay by using `(sit-for 0)'.
  1151.  
  1152.      If NODISP is non-`nil', then `sit-for' does not redisplay, but it
  1153.      still returns as soon as input is available (or when the timeout
  1154.      elapses).
  1155.  
  1156.      The usual purpose of `sit-for' is to give the user time to read
  1157.      text that you display.
  1158.  
  1159.  - Function: sleep-for SECONDS
  1160.      This function simply pauses for SECONDS seconds without updating
  1161.      the display.  This function pays no attention to available input.
  1162.      It returns `nil'.
  1163.  
  1164.      The argument SECONDS need not be an integer.  If it is a floating
  1165.      point number, `sleep-for' waits for a fractional number of seconds.
  1166.  
  1167.      Use `sleep-for' when you wish to guarantee a delay.
  1168.  
  1169.    *Note Time of Day::, for functions to get the current time.
  1170.  
  1171.